export default {
  namespaced:true,
  state:()=>({
    address:JSON.parse(uni.getStorageSync('address')||'{}'),
    token:uni.getStorageSync('token')||'',
    userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
    // 重定向
    redirectInfo:null
  }),
  mutations:{
    // 更新收货地址
    updataAddress(state,address){
      // console.log('a');
      state.address = address
      this.commit('m_address/saveAddressToStorage')
    },
    // 持久化储存
    saveAddressToStorage(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    // 更新用户info基本信息 持久化
    updateUserInfo(state,userinfo){
      // console.log(userinfo);
      state.userinfo = userinfo
      this.commit('m_address/saveUserInfoToStorage')
    },
    saveUserInfoToStorage(state){
      uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
    },
    // 修改token
    updataToken(state,token){
      state.token = token
      // console.log(token);
      this.commit('m_address/saveTokenToStorage')
    },
    saveTokenToStorage(state){
      // JSON.stringify()
      uni.setStorageSync('token',state.token)
    },
    // 重定向信息对象
    updateRedirectInfo(state,info){
      state.redirectInfo = info
    },
    // 
  },  
  
  actions:{},
  getters:{
    addstr(state){
      if(!state.address.provinceName) return 
      return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
    }
  }
}